home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 1.iso / DEMON / LANGUAGE / POTSRC.ARC / src / c / POT_Compil < prev    next >
Text File  |  1995-05-06  |  2KB  |  142 lines

  1. #include <pOtRTL.h>
  2. #include "POT.h"
  3. #include <stddef.h>
  4. #include <stdlib.h>
  5. #include <stdio.h>
  6. #include <signal.h>
  7.  
  8. #ifdef __sun__
  9. #define atexit(x) on_exit(x,NULL)
  10. # ifndef L_tmpnam
  11. # define L_tmpnam 1024
  12. # endif
  13. #endif
  14.  
  15. #ifdef __MSDOS__
  16. # ifdef __TURBOC__
  17. extern unsigned _stklen = 32768;
  18. # endif
  19. #endif
  20.  
  21. #ifdef __riscos
  22. # define unlink remove
  23.  
  24. #include "kernel.h"
  25. #include <string.h>
  26.  
  27. #define DDE_Prefix 0x42580
  28.  
  29. static int home_set = 0;
  30.  
  31. static void set_home(const char *path)
  32. {
  33.   _kernel_swi_regs regs;
  34.   char buffer[512];
  35.  
  36.   if (*path == '@') return;
  37.  
  38.   strcpy(buffer, path);
  39.   strcat(buffer, ".^.^.");
  40.  
  41.   /* fprintf(stderr, "Home: %s\n", &buffer); */
  42.  
  43.   regs.r[0] = (int) &buffer;
  44.   if (_kernel_swi(DDE_Prefix, ®s, ®s) == NULL)
  45.     home_set = 1;
  46.  
  47.   return;
  48. }
  49.  
  50. static void unset_home(void)
  51. {
  52.   if (home_set) {
  53.  
  54.     _kernel_swi_regs regs;
  55.     regs.r[0] = 0;
  56.     (void)_kernel_swi(DDE_Prefix, ®s, ®s);
  57.  
  58.   }
  59.  
  60.   return;
  61. }
  62.  
  63. #endif
  64.  
  65. pOt_LONGINT pOt__gc_heapthreshold = 65536;
  66.  
  67. static FILE *parfp;
  68.  
  69. void catch(signo)
  70.     int signo;
  71. {
  72.   switch(signo) {
  73.     case SIGINT: pOt__halt(__FILE__,__LINE__,22); break;
  74.     case SIGFPE: pOt__halt(__FILE__,__LINE__,14); break;
  75.     default: pOt__halt(__FILE__,__LINE__,16); break;
  76.   }
  77. }
  78.  
  79. static void rmparfile()
  80. {
  81.   fclose(parfp);
  82.   unlink(pOt__parfilename);
  83.   free(pOt__parfilename);
  84.  
  85. #ifdef __riscos
  86.   unset_home();
  87. #endif
  88.  
  89. }
  90.  
  91. int main(int argc, char *argv[])
  92. {
  93.   FILE *nestedfp;
  94.   int ch;
  95.  
  96.   parfp = NULL;
  97.   nestedfp = NULL;
  98.  
  99.   signal(SIGINT, catch);
  100.   signal(SIGFPE, catch);
  101.  
  102.   if((pOt__parfilename = malloc(L_tmpnam))==NULL) {
  103.     fprintf(stderr, "%s\n", "Not enough memory to start the program.");
  104.     exit(255);
  105.   }
  106.   tmpnam(pOt__parfilename);
  107.   parfp = fopen(pOt__parfilename, "w");
  108.   if(parfp == NULL) {
  109.     fprintf(stderr, "%s %s.\n", "Cannot create ", pOt__parfilename);
  110.     exit(255);
  111.   }
  112.  
  113. #ifdef __riscos
  114.   /* fprintf(stderr, "File: %s\n", argv[argc - 1]); */
  115.   set_home(argv[argc - 1]);
  116. #endif
  117.  
  118.   while(*(++argv)) {
  119. #ifdef __riscos
  120.     if((*argv)[0] == '!') {
  121. #else
  122.     if((*argv)[0] == '@') {
  123. #endif
  124.       nestedfp = fopen((*argv + 1), "r");
  125.       if(nestedfp == NULL) fprintf(stderr, "%s not found.\n", (*argv + 1));
  126.       else {
  127.         while((ch = fgetc(nestedfp)) != EOF) fputc(ch, parfp);
  128.         fputc('\n', parfp);
  129.         fclose(nestedfp);
  130.       }
  131.     } else fprintf(parfp, "%s\n", *argv);
  132.   }
  133.   fclose(parfp);
  134.   atexit(rmparfile);
  135.  
  136.   pOt_POT__body();
  137.   pOt_Compile_POT();
  138.  
  139.   exit(0);
  140.   return 0;
  141. }
  142.